package com.looookme.shaozhuo.datasave;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Shaozhuo on 2015/9/11.
 */
public class DataSaveList extends Activity {
    private List<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initData();
    }

    private void initData() {
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);
        setContentView(ll);

        ListView mListView = new ListView(this);
        mListView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        ll.addView(mListView);

        mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData()));
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                switch (position){
                    case 0:
                        intent.setClass(DataSaveList.this, Data_SharePreferences.class);
                        break;
                    case 1:
                        intent.setClass(DataSaveList.this, Data_SqlLite.class);
                        break;
                    case 2:
                        intent.setClass(DataSaveList.this, Data_SqlLiteOpenHelper.class);
                        break;
                    case 3:
                        intent.setClass(DataSaveList.this, Data_ContentProvider.class);
                        break;
                }
                startActivity(intent);
            }
        });
    }

    public List<String> getData() {
        data = new ArrayList<String>();
        data.add("SharedPreferences");
        data.add("SqlLite");
        data.add("SqlLiteHelper");
        data.add("ContentProvider");

        return data;
    }
}
